﻿var CustomerIMGPartial = {};
CustomerIMGPartial.init = function () {
    /*备注鼠标滑过弹层*/
    $(".icon-remark").hover(function () {
        if ($('#remark' + $(this).attr('propertyKeyid') + ' li').html().length > 3) {
            $("#remark" + $(this).attr("propertyKeyid")).show();
        }

    }, function () {
        $("#remark" + $(this).attr("propertyKeyid")).hide();
    });
    //
    var tabObj = $('#imgTextList th');
    if ($('#hiddenSortValue').val() != '') {
        for (var i = 0; i < tabObj.length; i++) {
            if ($(tabObj[i]).attr('callValue')) {
                if ($(tabObj[i]).attr('callValue').split('-')[0] == $('#hiddenSortValue').val().split('-')[0]) {

                    if ($('#hiddenSortValue').val().split('-')[1] == 'asc') {
                        $(tabObj[i].childNodes[0]).attr('class', 'sort-up');
                        $(tabObj[i]).attr('callValue', $('#hiddenSortValue').val().split('-')[0] + '-desc');
                        break;
                    }
                    $(tabObj[i].childNodes[0]).attr('class', 'sort-down');
                    $(tabObj[i]).attr('callValue', $('#hiddenSortValue').val().split('-')[0] + '-asc');
                    break;
                }
            }
        }
    }
    $('#imgTextList th').click(function () {
        var resultVal = $(this).attr('callValue');
        if (resultVal) {
            $('#hiddenSortValue').val(resultVal);
            $('#searchForm').submit();
            if ($(window).scrollTop() > $("#ajaxPages").offset().top) {
                $(window).scrollTop(0);
            }
        }
    });

    //看客户
    $(".see-owner").bind("click", function () {

        $.dialog({
            id: "seeOwner",
            title: "看客户",
            lock: true,
            background: "#808080",
            opacity: 0.87,
            content: $("#seeOwner").html()
        });
        var urlNum = $(this).attr("keyid");
        $.ajax({
            type: 'post',
            url: '/Customer/inquiry-contacts-find',
            data: { 'KeyId': urlNum },
            success: function (data) {
                $("#seeOwnerdiv").html(data);
                $("#writeFollowHref").attr("href", "/customer/inquiry-details?keyId=" + urlNum + "#maodian");

            }
        });

    });

    //插入跟进列表图文列表
    $("#gdIndexCustomerList .js-follow").unbind("click");
    $("#gdIndexCustomerList .js-follow").bind("click", function () {
        var currentElement = $(this);
        var keyId = currentElement.attr('keyid');
        var row = $(this).parent().parent().parent();
        var isOpenCurrentFollow = $(this).attr("follow-open");
        var keyid = currentElement.attr("keyid");
        if (isOpenCurrentFollow == "true") {
            $("#divItem" + keyid).next().next().remove();
            $(this).attr("follow-open", "false");
            return;
        }

        var currRowIndex = row[0].rowIndex;
        var followType = currentElement.attr('followType');
        var reqData = {
            'followType': followType,
            'ColumnCount': 13,
            'customerKeyId': keyId
        };
        $.AjaxAgency("/customer/inquiry-follow-for-list", reqData, function (data) {
            if (data.indexOf('pageDiscription="我是错误页"') > -1) {
                $.OKDialogAgency('<div class="tc">请求失败！</div>');
            } else {
                if (currentElement.attr("follow-open") != "true") {
                    currentElement.css("background-position", "-127px -189px");
                    $("#divItem" + keyid).next().after(data);
                    currentElement.attr("follow-open", "true");
                }
            }
        });

    });
}